/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jugueteria_lm;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Gorda
 */
public class Proveedor extends javax.swing.JFrame {

    Conexion conectar = new Conexion();
    Jugueteria_Datos obj = new Jugueteria_Datos();

    public Proveedor() {
        initComponents();
        MostrarJuguete("");
        MostrarProveedor("");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        Tjuguete = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jug1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jug2 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jug3 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jug4 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jug5 = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jug6 = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jug7 = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        buscaPro = new javax.swing.JTextField();
        jButton16 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        TProveedor = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jButton17 = new javax.swing.JButton();
        Prov5 = new javax.swing.JTextField();
        Prov4 = new javax.swing.JTextField();
        Prov3 = new javax.swing.JTextField();
        Prov2 = new javax.swing.JTextField();
        Prov1 = new javax.swing.JTextField();
        jButton18 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(255, 102, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setText("mostrar juguete");
        jButton1.setActionCommand("Mostrar Juguete");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        Tjuguete.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(Tjuguete);

        jPanel1.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 49, 740, 155));

        jLabel5.setText("ID Juguete");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 215, -1, -1));

        jug1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jug1ActionPerformed(evt);
            }
        });
        jPanel1.add(jug1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 235, 53, -1));

        jLabel6.setText("Nombre");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 215, -1, -1));

        jug2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jug2ActionPerformed(evt);
            }
        });
        jPanel1.add(jug2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 235, 83, -1));

        jLabel7.setText("Marca");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 215, -1, -1));
        jPanel1.add(jug3, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 235, 67, -1));

        jLabel8.setText("Precio unitario");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(285, 215, -1, -1));

        jug4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jug4ActionPerformed(evt);
            }
        });
        jPanel1.add(jug4, new org.netbeans.lib.awtextra.AbsoluteConstraints(285, 235, 52, -1));

        jLabel9.setText("Area");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(371, 215, 47, -1));
        jPanel1.add(jug5, new org.netbeans.lib.awtextra.AbsoluteConstraints(369, 235, 47, -1));

        jLabel25.setText("Cantidad de Juguetes");
        jPanel1.add(jLabel25, new org.netbeans.lib.awtextra.AbsoluteConstraints(436, 215, -1, -1));
        jPanel1.add(jug6, new org.netbeans.lib.awtextra.AbsoluteConstraints(461, 235, 54, -1));

        jLabel26.setText("Proveedor");
        jPanel1.add(jLabel26, new org.netbeans.lib.awtextra.AbsoluteConstraints(573, 215, -1, -1));
        jPanel1.add(jug7, new org.netbeans.lib.awtextra.AbsoluteConstraints(573, 236, 50, -1));

        jButton8.setText("Agregar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 235, 79, -1));

        jButton7.setText("Actualizar");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 280, -1, -1));

        jButton11.setText("Modificar");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton11, new org.netbeans.lib.awtextra.AbsoluteConstraints(99, 280, -1, -1));

        jButton12.setText("Nuevo");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(184, 280, 93, -1));

        jButton9.setText("Eliminar");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(295, 280, 79, -1));

        jButton10.setText("Buscar");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(404, 280, 79, -1));

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(501, 281, 55, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 4, 760, 340));

        jButton2.setText("Mostrar proveedor");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 399, -1, -1));

        jButton13.setText("Actualizar");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 460, -1, -1));

        jButton14.setText("Eliminar");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton14, new org.netbeans.lib.awtextra.AbsoluteConstraints(107, 460, 79, -1));

        jButton15.setText("Buscar");
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 501, 79, -1));
        getContentPane().add(buscaPro, new org.netbeans.lib.awtextra.AbsoluteConstraints(107, 502, 79, -1));

        jButton16.setText("Modificar");
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton16, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 542, -1, -1));

        TProveedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane3.setViewportView(TProveedor);

        getContentPane().add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 428, 539, 155));

        jLabel10.setText("Id Proveedor");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 601, -1, -1));

        jLabel11.setText("Nombre");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(286, 601, -1, -1));

        jLabel12.setText("procedencia");
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(379, 601, -1, -1));

        jLabel13.setText("Telefono");
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(468, 601, -1, -1));

        jLabel14.setText("Cantidad de Cajas");
        getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(536, 601, -1, -1));

        jButton17.setText("Agregar");
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton17, new org.netbeans.lib.awtextra.AbsoluteConstraints(656, 609, 79, -1));
        getContentPane().add(Prov5, new org.netbeans.lib.awtextra.AbsoluteConstraints(561, 621, 47, -1));

        Prov4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Prov4ActionPerformed(evt);
            }
        });
        getContentPane().add(Prov4, new org.netbeans.lib.awtextra.AbsoluteConstraints(468, 621, 52, -1));
        getContentPane().add(Prov3, new org.netbeans.lib.awtextra.AbsoluteConstraints(379, 621, 67, -1));

        Prov2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Prov2ActionPerformed(evt);
            }
        });
        getContentPane().add(Prov2, new org.netbeans.lib.awtextra.AbsoluteConstraints(286, 621, 83, -1));

        Prov1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Prov1ActionPerformed(evt);
            }
        });
        getContentPane().add(Prov1, new org.netbeans.lib.awtextra.AbsoluteConstraints(196, 621, 63, -1));

        jButton18.setText("Nuevo");
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton18, new org.netbeans.lib.awtextra.AbsoluteConstraints(93, 542, 93, -1));

        jButton3.setBackground(new java.awt.Color(255, 0, 0));
        jButton3.setText("Salir");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(656, 680, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
       MostrarProveedor("");
    }//GEN-LAST:event_jButton2ActionPerformed

    void MostrarProveedor(String prov){
     DefaultTableModel ModeloProveedor = new DefaultTableModel();

       ModeloProveedor.addColumn("ID proveedor");
        ModeloProveedor.addColumn("Nombre");
        ModeloProveedor.addColumn("Procedencia");
        ModeloProveedor.addColumn("Telefono");
       ModeloProveedor.addColumn("Cantidad de cajas");

        TProveedor.setModel(ModeloProveedor);
        String sql = "";
        if(prov.equals("")){
            
            sql = "SELECT * FROM proveedores";
        }
        else {
         sql = "SELECT * FROM proveedores WHERE idproveedor = '"+prov+"'";
        }
        String[] datosProve = new String[5];
        try {
            Statement st = conectar.getConnection().createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                datosProve[0] = rs.getString(1);
                datosProve[1] = rs.getString(2);
                datosProve[2] = rs.getString(3);
                datosProve[3] = rs.getString(4);
                datosProve[4] = rs.getString(5);

                ModeloProveedor.addRow(datosProve);

            }
            TProveedor.setModel(ModeloProveedor);
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }
    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        // TODO add your handling code here://actualizar empleado
        try {

            PreparedStatement pre = conectar.getConnection().prepareStatement("UPDATE proveedores "
                    + "SET nombre='" + Prov2.getText() + "', estado='" + Prov3.getText() 
                    + "',telefono='" + Prov4.getText()+ "',cantidad_cajas='" + Prov5.getText()
                    + "' WHERE idproveedor='" + Prov1.getText() + "';");
            pre.executeUpdate();

            JOptionPane.showMessageDialog(this, "Se Actualizo Empleado con Exito");
            MostrarProveedor("");
        } catch (SQLException ex) {
            //JOptionPane.showMessageDialog(this, "Error al Corregir");
            System.out.print(ex.getMessage());
        }
    }//GEN-LAST:event_jButton13ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        // TODO add your handling code here://eliminar Pro
        int fild = TProveedor.getSelectedRow();
        if (fild > -1) {
            String id = String.valueOf(TProveedor.getValueAt(fild, 0));
            obj.Elimina_Datos("proveedores", "idproveedor", id);
            MostrarProveedor("");
            fild = -1;
        }
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
        // TODO add your handling code here:
        MostrarProveedor(buscaPro.getText());
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
        // TODO add your handling code here:
        int fila2 = TProveedor.getSelectedRow();
        if (fila2 >= 0) {
            Prov1.setText(TProveedor.getValueAt(fila2, 0).toString());
            Prov2.setText(TProveedor.getValueAt(fila2, 1).toString());
            Prov3.setText(TProveedor.getValueAt(fila2, 2).toString());
            Prov4.setText(TProveedor.getValueAt(fila2, 3).toString());
            Prov5.setText(TProveedor.getValueAt(fila2, 4).toString());

        } else {
            JOptionPane.showMessageDialog(null, "Seleccionado una fila por favor");

        }
    }//GEN-LAST:event_jButton16ActionPerformed

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
        // TODO add your handling code here://Agregar tablaProveedo
        try {
            try (PreparedStatement insertar = conectar.getConnection().prepareStatement("insert into proveedores(idproveedor, nombre, estado, telefono, cantidad_cajas) "
                            + " values(?,?,?,?,?)")) {
                insertar.setString(1, Prov1.getText());
                insertar.setString(2, Prov2.getText());
                insertar.setString(3, Prov3.getText());
                insertar.setString(4, Prov4.getText());
                insertar.setString(5, Prov5.getText());
                insertar.execute();
                insertar.close();
                JOptionPane.showMessageDialog(null, "Proveedor Agregado");
                MostrarProveedor("");
            }
        } catch (SQLException e) {
            System.out.print(e.getMessage());
            //JOptionPane.showMessageDialog(null, "ID (" + camp1.getText() + ") en uso..");
        }
    }//GEN-LAST:event_jButton17ActionPerformed

    void MostrarJuguete(String juguete) {
        DefaultTableModel ModeloJuguete = new DefaultTableModel();

        ModeloJuguete.addColumn("ID juguete");
        ModeloJuguete.addColumn("Nombre ");
        ModeloJuguete.addColumn("Marca");
        ModeloJuguete.addColumn("Precio unitario");
        ModeloJuguete.addColumn("Area");
        ModeloJuguete.addColumn("cantidad de piezas");
        ModeloJuguete.addColumn("Proveedor");

        Tjuguete.setModel(ModeloJuguete);
        String sql = "";
        if (juguete.equals("")) {

            sql = "SELECT * FROM juguete";
        } else {
            sql = "SELECT * FROM juguete WHERE id_juguete ='" + juguete + "'";
        }
        String[] datosjug = new String[7];
        try {
            Statement st = conectar.getConnection().createStatement();
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                datosjug[0] = rs.getString(1);
                datosjug[1] = rs.getString(2);
                datosjug[2] = rs.getString(3);
                 datosjug[3] = rs.getString(4);
                  datosjug[4] = rs.getString(5);
                    datosjug[5] = rs.getString(6);
                datosjug[6] = rs.getString(7);


                ModeloJuguete.addRow(datosjug);

            }
            Tjuguete.setModel(ModeloJuguete);
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }

    private void Prov4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Prov4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Prov4ActionPerformed

    private void Prov1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Prov1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Prov1ActionPerformed

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed
        // TODO add your handling code here:
        Prov1.setText(null);
        Prov2.setText(null);
        Prov3.setText(null);
        Prov4.setText(null);
        Prov5.setText(null);
    }//GEN-LAST:event_jButton18ActionPerformed

    private void Prov2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Prov2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_Prov2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
         this.setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        // TODO add your handling code here:
        MostrarJuguete(jTextField1.getText());
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here://eliminar empleado
        int fild = Tjuguete.getSelectedRow();
        if (fild > -1) {

            String id = String.valueOf(Tjuguete.getValueAt(fild, 0));
            obj.Elimina_Datos("juguete", "id_juguete", id);
            MostrarJuguete("");
            fild = -1;
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
        // TODO add your handling code here:

        jug1.setText(null);
        jug2.setText(null);
        jug3.setText(null);
        jug4.setText(null);
        jug5.setText(null);
        jug6.setText(null);
        jug7.setText(null);
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        // TODO add your handling code here:
        int fila2 = Tjuguete.getSelectedRow();
        if (fila2 >= 0) {
            jug1.setText(Tjuguete.getValueAt(fila2, 0).toString());
            jug2.setText(Tjuguete.getValueAt(fila2, 1).toString());
            jug3.setText(Tjuguete.getValueAt(fila2, 2).toString());
            jug4.setText(Tjuguete.getValueAt(fila2, 3).toString());
            jug5.setText(Tjuguete.getValueAt(fila2, 4).toString());
            jug6.setText(Tjuguete.getValueAt(fila2, 5).toString());
            jug7.setText(Tjuguete.getValueAt(fila2, 6).toString());

        } else {
            JOptionPane.showMessageDialog(null, "Seleccionado una fila por favor");

        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here://actualizar juguete
        try {

            PreparedStatement pre = conectar.getConnection().prepareStatement("UPDATE juguete "
                + "SET nombrejuguete='" + jug2.getText() + "', marca='" + jug3.getText() + "', precio_unit='" + jug4.getText()
                + "', area='" + jug5.getText() + "', cantidad_piezas='" + jug6.getText() + "', proveedores_idproveedor='" + jug7.getText()
                + "' WHERE id_juguete='" + jug1.getText() + "';");
            pre.executeUpdate();

            JOptionPane.showMessageDialog(this, "Se Actualizo Juguete con Exito");
            MostrarJuguete("");
        } catch (SQLException ex) {
            //JOptionPane.showMessageDialog(this, "Error al Corregir");
            System.out.print(ex.getMessage());
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here://Agregar tabla juguete
        try {
            try (PreparedStatement insertar = conectar.getConnection().prepareStatement("insert into "
                + "juguete(id_juguete, nombrejuguete, marca, precio_unit, area, "
                + "cantidad_piezas, proveedores_idproveedor) "
                + " values(?,?,?,?,?,?,?)")) {
            insertar.setString(1, jug1.getText());
            insertar.setString(2, jug2.getText());
            insertar.setString(3, jug3.getText());
            insertar.setString(4, jug4.getText());
            insertar.setString(5, jug5.getText());
            insertar.setString(6, jug6.getText());
            insertar.setString(7, jug7.getText());
            insertar.execute();
            insertar.close();
            JOptionPane.showMessageDialog(null, "juguete Agregado");
            MostrarJuguete("");
        }
        } catch (SQLException e) {
            System.out.print(e.getMessage());
            //JOptionPane.showMessageDialog(null, "ID (" + camp1.getText() + ") en uso..");
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jug4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jug4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jug4ActionPerformed

    private void jug2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jug2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jug2ActionPerformed

    private void jug1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jug1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jug1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        MostrarJuguete("");
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Proveedor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Proveedor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField Prov1;
    private javax.swing.JTextField Prov2;
    private javax.swing.JTextField Prov3;
    private javax.swing.JTextField Prov4;
    private javax.swing.JTextField Prov5;
    private javax.swing.JTable TProveedor;
    private javax.swing.JTable Tjuguete;
    private javax.swing.JTextField buscaPro;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jug1;
    private javax.swing.JTextField jug2;
    private javax.swing.JTextField jug3;
    private javax.swing.JTextField jug4;
    private javax.swing.JTextField jug5;
    private javax.swing.JTextField jug6;
    private javax.swing.JTextField jug7;
    // End of variables declaration//GEN-END:variables
}
